package com.cac.demo.newCode.sorting.controller;

import com.cac.demo.newCode.sorting.dto.SortingTaskDTO;
import com.cac.demo.newCode.sorting.service.SortingTaskService;
import com.cac.demo.service.pointPackageSort.PointPackageSortService;
import com.cac.demo.util.adapter.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RequestMapping("/SortingPackageTask")
@RestController
@Slf4j
@Api(tags = "分拣作业")
public class SortingPackageTaskController {
    @Resource
    private SortingTaskService sortingTaskService;
    @Resource
    private PointPackageSortService pointPackageSortService;

    @PostMapping("/getConsole")
    @ApiOperation(value = "PDA扫描分拣台")
    public ResponseMsg<Object> getConsole(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.getConsole(sortingTaskDTO);
    }

    @PostMapping("/AOSortingTaskPage")
    @ApiOperation(value = "AO分拣任务列表")
    public ResponseMsg<Object> AOSortingTaskPage(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.AOSortingTaskPage(sortingTaskDTO);
    }

    @PostMapping("/materialDistribution")
    @ApiOperation(value = "缓存箱任务下发")
    public ResponseMsg<Object> materialDistribution() {
        return sortingTaskService.materialDistribution();
    }

    @PostMapping("/startSortingTask")
    @ApiOperation(value = "开始作业")
    public ResponseMsg<Object> startSortingTask(@RequestBody List<SortingTaskDTO> sortingTaskDTOs) {
        return sortingTaskService.startSortingTask(sortingTaskDTOs);
    }

    @PostMapping("/pauseSortingTask")
    @ApiOperation(value = "暂停作业")
    public ResponseMsg<Object> pauseSortingTask(@RequestBody List<SortingTaskDTO> sortingTaskDTOs) {
        return sortingTaskService.pauseSortingTask(sortingTaskDTOs);
    }

    @PostMapping("/getWorkBinAndTool")
    @ApiOperation(value = "查看缓存箱和托盘")
    public ResponseMsg<Object> getWorkBinAndTool(@RequestBody List<SortingTaskDTO> sortingTaskDTOs) {
        return sortingTaskService.getWorkBinAndTool(sortingTaskDTOs);
    }

    @PostMapping("/viewWorkBin")
    @ApiOperation(value = "查看缓存箱")
    public ResponseMsg<Object> viewWorkBin() {
        return sortingTaskService.viewWorkBin();
    }

    @PostMapping("/getToolCode")
    @ApiOperation(value = "托盘查询")
    public ResponseMsg<Object> getToolCode(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.getToolCode(sortingTaskDTO);
    }

    @PostMapping("/scanConfirmMaterialList")
    @ApiOperation(value = "缓存箱扫码")
    public ResponseMsg<Object> scanConfirmMaterialList(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.scanConfirmMaterialList(sortingTaskDTO);
    }

    @PostMapping("/scanConfirmMaterialPage")
    @ApiOperation(value = "扫码确认的物料分页")
    public ResponseMsg<Object> scanConfirmMaterialPage(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.scanConfirmMaterialPage(sortingTaskDTO);
    }

    @PostMapping("/cleanWaitingTask")
    @ApiOperation(value = "清理等待任务")
    public ResponseMsg<Object> cleanWaitingTask() {
        return sortingTaskService.cleanWaitingTask();
    }

    @PostMapping("/bindingWorkBin")
    @ApiOperation(value = "绑定托盘箱子")
    public ResponseMsg<Object> bindingWorkBin() {
        return sortingTaskService.bindingWorkBin();
    }

    @PostMapping("/callWorkBin")
    @ApiOperation(value = "叫箱")
    public ResponseMsg<Object> callWorkBin(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.callWorkBin(sortingTaskDTO);
    }

    @PostMapping("/SameDrawingMaterial")
    @ApiOperation(value = "相同图纸的物料")
    public ResponseMsg<Object> SameDrawingMaterial(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.SameDrawingMaterial(sortingTaskDTO);
    }

    @PostMapping("replaceMatchInfo")
    @ApiOperation(value = "物料替换保存")
    public ResponseMsg replaceMatchInfo(@RequestBody HashMap map) {
        HashMap sourceMatch = (HashMap) map.get("sourceMatch");
        List<HashMap> replaceMatchList = (List<HashMap>) map.get("replaceMatchList");
        return pointPackageSortService.replaceMatchInfo(sourceMatch, replaceMatchList);
    }

    @PostMapping("replaceToolCode")
    @ApiOperation(value = "更换托盘")
    public ResponseMsg<Object> replaceToolCode(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.replaceToolCode(sortingTaskDTO);
    }

    @PostMapping("replaceToolCodeByHand")
    @ApiOperation(value = "手动更换托盘")
    public ResponseMsg<Object> replaceToolCodeByHand(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.replaceToolCodeByHand(sortingTaskDTO);
    }

    @PostMapping("SortingSaveRemark")
    @ApiOperation(value = "保存备注")
    public ResponseMsg<Object> SortingSaveRemark(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.SortingSaveRemark(sortingTaskDTO);
    }

    @PostMapping("getPackCode")
    @ApiOperation(value = "查看工作包规则")
    public ResponseMsg<Object> getPackCode(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.getPackCode(sortingTaskDTO);
    }

    @PostMapping("getMaterial")
    @ApiOperation(value = "工作包-查看物料信息")
    public ResponseMsg<Object> getMaterial(@RequestBody SortingTaskDTO sortingTaskDTO) {
        return sortingTaskService.getMaterial(sortingTaskDTO);
    }

}
